home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / distutils / unixccompiler.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  7KB  |  228 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''distutils.unixccompiler
  5.  
  6. Contains the UnixCCompiler class, a subclass of CCompiler that handles
  7. the "typical" Unix-style command-line C compiler:
  8.   * macros defined with -Dname[=value]
  9.   * macros undefined with -Uname
  10.   * include search directories specified with -Idir
  11.   * libraries specified with -lllib
  12.   * library search directories specified with -Ldir
  13.   * compile handled by \'cc\' (or similar) executable with -c option:
  14.     compiles .c to .o
  15.   * link static library handled by \'ar\' command (possibly with \'ranlib\')
  16.   * link shared library handled by \'cc -shared\'
  17. '''
  18. __revision__ = '$Id: unixccompiler.py,v 1.56 2004/08/29 16:40:55 loewis Exp $'
  19. import os
  20. import sys
  21. from types import StringType, NoneType
  22. from copy import copy
  23. from distutils import sysconfig
  24. from distutils.dep_util import newer
  25. from distutils.ccompiler import CCompiler, gen_preprocess_options, gen_lib_options
  26. from distutils.errors import DistutilsExecError, CompileError, LibError, LinkError
  27. from distutils import log
  28.  
  29. class UnixCCompiler(CCompiler):
  30.     compiler_type = 'unix'
  31.     executables = {
  32.         'preprocessor': None,
  33.         'compiler': [
  34.             'cc'],
  35.         'compiler_so': [
  36.             'cc'],
  37.         'compiler_cxx': [
  38.             'cc'],
  39.         'linker_so': [
  40.             'cc',
  41.             '-shared'],
  42.         'linker_exe': [
  43.             'cc'],
  44.         'archiver': [
  45.             'ar',
  46.             '-cr'],
  47.         'ranlib': None }
  48.     if sys.platform[:6] == 'darwin':
  49.         executables['ranlib'] = [
  50.             'ranlib']
  51.     
  52.     src_extensions = [
  53.         '.c',
  54.         '.C',
  55.         '.cc',
  56.         '.cxx',
  57.         '.cpp',
  58.         '.m']
  59.     obj_extension = '.o'
  60.     static_lib_extension = '.a'
  61.     shared_lib_extension = '.so'
  62.     dylib_lib_extension = '.dylib'
  63.     static_lib_format = shared_lib_format = dylib_lib_format = 'lib%s%s'
  64.     if sys.platform == 'cygwin':
  65.         exe_extension = '.exe'
  66.     
  67.     
  68.     def preprocess(self, source, output_file = None, macros = None, include_dirs = None, extra_preargs = None, extra_postargs = None):
  69.         (ignore, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
  70.         pp_opts = gen_preprocess_options(macros, include_dirs)
  71.         pp_args = self.preprocessor + pp_opts
  72.         if output_file:
  73.             pp_args.extend([
  74.                 '-o',
  75.                 output_file])
  76.         
  77.         if extra_preargs:
  78.             pp_args[:0] = extra_preargs
  79.         
  80.         if extra_postargs:
  81.             pp_args.extend(extra_postargs)
  82.         
  83.         pp_args.append(source)
  84.         if self.force and output_file is None or newer(source, output_file):
  85.             if output_file:
  86.                 self.mkpath(os.path.dirname(output_file))
  87.             
  88.             
  89.             try:
  90.                 self.spawn(pp_args)
  91.             except DistutilsExecError:
  92.                 msg = None
  93.                 raise CompileError, msg
  94.             except:
  95.                 None<EXCEPTION MATCH>DistutilsExecError
  96.             
  97.  
  98.         None<EXCEPTION MATCH>DistutilsExecError
  99.  
  100.     
  101.     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
  102.         
  103.         try:
  104.             self.spawn(self.compiler_so + cc_args + [
  105.                 src,
  106.                 '-o',
  107.                 obj] + extra_postargs)
  108.         except DistutilsExecError:
  109.             msg = None
  110.             raise CompileError, msg
  111.  
  112.  
  113.     
  114.     def create_static_lib(self, objects, output_libname, output_dir = None, debug = 0, target_lang = None):
  115.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  116.         output_filename = self.library_filename(output_libname, output_dir = output_dir)
  117.         if self._need_link(objects, output_filename):
  118.             self.mkpath(os.path.dirname(output_filename))
  119.             self.spawn(self.archiver + [
  120.                 output_filename] + objects + self.objects)
  121.             if self.ranlib:
  122.                 
  123.                 try:
  124.                     self.spawn(self.ranlib + [
  125.                         output_filename])
  126.                 except DistutilsExecError:
  127.                     msg = None
  128.                     raise LibError, msg
  129.                 except:
  130.                     None<EXCEPTION MATCH>DistutilsExecError
  131.                 
  132.  
  133.             None<EXCEPTION MATCH>DistutilsExecError
  134.         else:
  135.             log.debug('skipping %s (up-to-date)', output_filename)
  136.  
  137.     
  138.     def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
  139.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  140.         (libraries, library_dirs, runtime_library_dirs) = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
  141.         lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries)
  142.         if type(output_dir) not in (StringType, NoneType):
  143.             raise TypeError, "'output_dir' must be a string or None"
  144.         
  145.         if output_dir is not None:
  146.             output_filename = os.path.join(output_dir, output_filename)
  147.         
  148.         if self._need_link(objects, output_filename):
  149.             ld_args = objects + self.objects + lib_opts + [
  150.                 '-o',
  151.                 output_filename]
  152.             if debug:
  153.                 ld_args[:0] = [
  154.                     '-g']
  155.             
  156.             if extra_preargs:
  157.                 ld_args[:0] = extra_preargs
  158.             
  159.             if extra_postargs:
  160.                 ld_args.extend(extra_postargs)
  161.             
  162.             self.mkpath(os.path.dirname(output_filename))
  163.             
  164.             try:
  165.                 if target_desc == CCompiler.EXECUTABLE:
  166.                     linker = self.linker_exe[:]
  167.                 else:
  168.                     linker = self.linker_so[:]
  169.                 if target_lang == 'c++' and self.compiler_cxx:
  170.                     linker[0] = self.compiler_cxx[0]
  171.                 
  172.                 self.spawn(linker + ld_args)
  173.             except DistutilsExecError:
  174.                 msg = None
  175.                 raise LinkError, msg
  176.             except:
  177.                 None<EXCEPTION MATCH>DistutilsExecError
  178.             
  179.  
  180.         None<EXCEPTION MATCH>DistutilsExecError
  181.         log.debug('skipping %s (up-to-date)', output_filename)
  182.  
  183.     
  184.     def library_dir_option(self, dir):
  185.         return '-L' + dir
  186.  
  187.     
  188.     def runtime_library_dir_option(self, dir):
  189.         compiler = os.path.basename(sysconfig.get_config_var('CC'))
  190.         if sys.platform[:6] == 'darwin':
  191.             return '-L' + dir
  192.         elif sys.platform[:5] == 'hp-ux':
  193.             return '+s -L' + dir
  194.         elif sys.platform[:7] == 'irix646' or sys.platform[:6] == 'osf1V5':
  195.             return [
  196.                 '-rpath',
  197.                 dir]
  198.         elif compiler[:3] == 'gcc' or compiler[:3] == 'g++':
  199.             return '-Wl,-R' + dir
  200.         else:
  201.             return '-R' + dir
  202.  
  203.     
  204.     def library_option(self, lib):
  205.         return '-l' + lib
  206.  
  207.     
  208.     def find_library_file(self, dirs, lib, debug = 0):
  209.         shared_f = self.library_filename(lib, lib_type = 'shared')
  210.         dylib_f = self.library_filename(lib, lib_type = 'dylib')
  211.         static_f = self.library_filename(lib, lib_type = 'static')
  212.         for dir in dirs:
  213.             shared = os.path.join(dir, shared_f)
  214.             dylib = os.path.join(dir, dylib_f)
  215.             static = os.path.join(dir, static_f)
  216.             if os.path.exists(dylib):
  217.                 return dylib
  218.                 continue
  219.             if os.path.exists(shared):
  220.                 return shared
  221.                 continue
  222.             if os.path.exists(static):
  223.                 return static
  224.                 continue
  225.         
  226.  
  227.  
  228.